using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 改变实体朝向
    /// 参数组1:1.实体tag或mcid，2.y轴旋转值，3.是否是增量
    /// </summary>
    public class ExecChangeEntityRotation : BaseServiceExecution
    {
        public override void Execute(LevelRegion region, LevelPlayer player)
        {
            var config = _config as ExecParamChangeEntityRotation;
            if (!config.tagOrMcid.TryGetValue(triggerEntity, out int tagOrMcid))
            {
                LogicLog.LogError("无法获取到tagOrMcid.");
                return;
            }
            int rotationY = config.rotationY;
            bool isIncrement = config.isIncrement;

            LevelEntity entity = tagOrMcid == 0 ? triggerEntity : region.GetEntityByTagOrMcid(tagOrMcid);

            if (entity == null)
            {
                LogicLog.LogError($"找不到指定的实体，rag or id：{tagOrMcid}");
                return;
            }

            entity.SetRotationY(rotationY, isIncrement, true);
        }
    }
}
